<%@ Page SmartNavigation="False" Language="C#" enableViewState="false" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<%@ Register TagPrefix="CSD" Namespace="CommunityServer.Discussions.Controls" Assembly="CommunityServer.Discussions" %>
<%@ Import Namespace="CommunityServer.Galleries.Components" %>
<%@ Import Namespace="CommunityServer.Blogs.Components" %>
<%@ Import Namespace="CommunityServer.Components" %>
<%@ Import Namespace="CommunityServer" %>

<script language="C#" runat="server">
	void Page_Load()
	{
		JavaScript.RenderAsJavaScript(this.Context);
	
		// locals
		User user;

		// acquire current context
		CSContext csContext = CSContext.Current;
		
		// if settings don't allow anonymous viewing of profiles, don't show badge
		if ((csContext.User.IsAnonymous) && (csContext.SiteSettings.RequireAuthenticationForProfiles))
		{
			badge.Visible = false;
			Context.Response.End();
		}

		int userID = csContext.UserID;
		if (userID <= 0)	// invalid user
		{
			// Is there a username?
			if (Context.Request.QueryString["UserName"] == string.Empty)
				throw new CSException(CSExceptionType.UserNotFound);
			else
				user = Users.GetUser(0, Context.Request.QueryString["UserName"], false, true);
		}
		else
		{
			user = Users.GetUser(csContext.UserID, false, true);
		}

		// don't show the anonymous user's badge
		if(user.IsAnonymous)
		{
			badge.Visible = false;
			Context.Response.End();
		}

		Users.ValidateUserAccess(user, csContext.User);

		SiteLink.Text = csContext.SiteSettings.SiteName;
		SiteLink.NavigateUrl = csContext.SiteSettings.SiteUrl;
		Username.Text =  (user.EnableDisplayName) ? user.DisplayName : user.Username;
		Username.NavigateUrl = Globals.GetSiteUrls().UserProfile(user.Username);
		Avatar.User = user;
		PostIcon.User = user;
		JoinedAttribute.User = user;
		LocationAttribute.User = user;
		PostsAttribute.User = user;
		PointsAttribute.User = user;
		RoleIcon.User = user;

		// Note: Disabling the "Powered By" text of the badge is a violation
		// of the Community Server Express Edition End User License Agreement
		//
		if (Telligent.Registration.CommunityServer.IsStandard && !csContext.SiteSettings.EnableEula)
			Footer.Visible = false;
	}
	
	
</script>

<asp:placeholder id="badge" runat="server">
	<style>
		#CommonBadge
		{
			margin: 0px;
			border: solid 1px <%= Request.QueryString["bordercolor"] == null ? "#cccccc" : Request.QueryString["bordercolor"] %>;	
			width: <%= Request.QueryString["width"] == null ? "180px" : Request.QueryString["width"] %>;
			overflow: hidden;
			font-family: Tahoma, Arial, Helvetica;
			font-size: <%= Request.QueryString["basefontsize"] == null ? "10pt" : Request.QueryString["basefontsize"] %>;
			color: <%= Request.QueryString["contentcolor"] == null ? "#000000" : Request.QueryString["contentcolor"] %>;
		}
		
		#CommonBadge a:link, #CommonBadge a:visited, #CommonBadge a:hover, #CommonBadge a:active
		{
			color: <%= Request.QueryString["linkcolor"] == null ? "#000000" : Request.QueryString["linkcolor"] %>;
		}

		.CommonBadgeHeader
		{
			padding: 6px;
			padding-left: 8px;
			border-bottom: solid 1px <%= Request.QueryString["bordercolor"] == null ? "#cccccc" : Request.QueryString["bordercolor"] %>;
			background-color: <%= Request.QueryString["headerbgcolor"] == null ? "#e2eecd" : Request.QueryString["headerbgcolor"] %>;
			font-size: 90%;
			font-weight: bold;
			margin: 0px;
			text-align: center;
		}

		.CommonBadgeContent
		{
			background-color: <%=Request.QueryString["contentbgcolor"] == null ? "#eeeeee" : Request.QueryString["contentbgcolor"] %>;
			padding: 8px;
		}

		UL.CommonBadgeContentList
		{
			margin: 0px;
			padding: 0px;
			list-style-type: none;	
			padding-left: 4px;
		}

		UL.CommonBadgeContentList LI
		{
			margin: 4px;
			margin-left: 2px;
			margin-right: 10px;
			font-size: 90%;
			text-align: center;
		}

		.CommonBadgeUserName
		{
			font-weight: bold;
		}

		.CommonBadgeAvatar
		{
		}

		.CommonBadgeFooter
		{
			margin-top: 10px;
			font-size: 70%;
			text-align: center;
		}
	</style>

	<div id="CommonBadge">
		<h4 class="CommonBadgeHeader">
			<asp:HyperLink runat="server" id="SiteLink" Target="_top" />
		</h4>
		<div class="CommonBadgeContent">
			<ul class="CommonBadgeContentList">
				<li class="CommonBadgeUserName">
					<asp:HyperLink runat="server" id="Username" Target="_top" />
				</li>
				<li class="CommonBadgeAvatar">
					<CS:UserAvatar runat="server" Border="1" PadImage="False" id="Avatar" />
				</li>
				<li>
					<CS:PostIcons runat="server" id="PostIcon" />
				</li>
				<li>
					<CS:UserAttribute FormatString="{0}" Attribute="Joined" runat="server" id="JoinedAttribute" Target="_top" />
				</li>
				<li>
					<CS:UserAttribute FormatString="{0}" Attribute="Location" runat="server" id="LocationAttribute" Target="_top" />
				</li>
				<li>
					<CS:UserAttribute FormatString="{0}" Attribute="Posts" runat="server" id="PostsAttribute" Target="_top" />
				</li>
				<li>
					<CS:UserAttribute FormatString="{0}" Attribute="Points" runat="server" id="PointsAttribute" Target="_top" />
				</li>
				<li>
					<CS:RoleIcons runat="server" id="RoleIcon" EnablePadding="false" Target="_top" />
				</li>
			</ul>						
			<div class="CommonBadgeFooter" id="Footer" runat="server">
				<CS:ResourceLabel resourcename="Badge_PoweredBy" runat="server" />
				<a href="http://communityserver.org/r.ashx?B" target="_top">Community Server</a>
			</div>
		</div>
	</div>
</asp:placeholder>



